package org.yoyo.classroom.controller;



import org.springframework.web.bind.annotation.*;
import org.yoyo.classroom.domain.po.Post;
import org.yoyo.classroom.service.PostService;

import java.util.List;

@RestController
@RequestMapping("/api/posts")
public class PostController {

    private final PostService postService;

    public PostController(PostService postService) {
        this.postService = postService;
    }

    @GetMapping
    public List<Post> getPosts(@RequestParam int page, @RequestParam int size) {
        return postService.getPosts(page, size);
    }

    @PostMapping
    public void createPost(@RequestBody Post post) {
        postService.createPost(post);
    }

    @GetMapping("/{id}")
    public Post getPostById(@PathVariable int id) {
        return postService.getPostById(id);
    }
}